/*
  Copyright � 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  ThanhNam ERP Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using VINETLIFE.DO;
/// <summary>
/// Summary description for cmsAccountDAL
/// </summary>
namespace VINETLIFE.DAL
{

    public class cmsAccountDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public cmsAccountDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(cmsAccountDO objcmsAccountDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsAccount_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@AccountCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsAccountDO.AccountCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CustomerId", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountDO.CustomerId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CustomerCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsAccountDO.CustomerCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsAccountDO.CreatedDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LastSaveDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsAccountDO.LastSaveDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedById", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountDO.CreatedById;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LastModifiedId", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountDO.LastModifiedId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SystemStatus", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsAccountDO.SystemStatus;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Deposite", SqlDbType.BigInt);
            Sqlparam.Value = objcmsAccountDO.Deposite;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DepositBeforeTran", SqlDbType.BigInt);
            Sqlparam.Value = objcmsAccountDO.DepositBeforeTran;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Note", SqlDbType.NText);
            Sqlparam.Value = objcmsAccountDO.Note;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(cmsAccountDO objcmsAccountDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsAccount_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@AccountId", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountDO.AccountId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@AccountCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsAccountDO.AccountCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CustomerId", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountDO.CustomerId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CustomerCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsAccountDO.CustomerCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsAccountDO.CreatedDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LastSaveDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsAccountDO.LastSaveDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedById", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountDO.CreatedById;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LastModifiedId", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountDO.LastModifiedId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SystemStatus", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsAccountDO.SystemStatus;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Deposite", SqlDbType.BigInt);
            Sqlparam.Value = objcmsAccountDO.Deposite;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DepositBeforeTran", SqlDbType.BigInt);
            Sqlparam.Value = objcmsAccountDO.DepositBeforeTran;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Note", SqlDbType.NText);
            Sqlparam.Value = objcmsAccountDO.Note;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(cmsAccountDO objcmsAccountDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsAccount_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@AccountId", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountDO.AccountId;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsAccount_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public cmsAccountDO Select(cmsAccountDO objcmsAccountDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsAccount_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@AccountId", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountDO.AccountId;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["AccountId"]))
                    objcmsAccountDO.AccountId = Convert.ToInt32(dr["AccountId"]);
                if (!Convert.IsDBNull(dr["AccountCode"]))
                    objcmsAccountDO.AccountCode = Convert.ToString(dr["AccountCode"]);
                if (!Convert.IsDBNull(dr["CustomerId"]))
                    objcmsAccountDO.CustomerId = Convert.ToInt32(dr["CustomerId"]);
                if (!Convert.IsDBNull(dr["CustomerCode"]))
                    objcmsAccountDO.CustomerCode = Convert.ToString(dr["CustomerCode"]);
                if (!Convert.IsDBNull(dr["CreatedDate"]))
                    objcmsAccountDO.CreatedDate = Convert.ToDateTime(dr["CreatedDate"]);
                if (!Convert.IsDBNull(dr["LastSaveDate"]))
                    objcmsAccountDO.LastSaveDate = Convert.ToDateTime(dr["LastSaveDate"]);
                if (!Convert.IsDBNull(dr["CreatedById"]))
                    objcmsAccountDO.CreatedById = Convert.ToInt32(dr["CreatedById"]);
                if (!Convert.IsDBNull(dr["LastModifiedId"]))
                    objcmsAccountDO.LastModifiedId = Convert.ToInt32(dr["LastModifiedId"]);
                if (!Convert.IsDBNull(dr["SystemStatus"]))
                    objcmsAccountDO.SystemStatus = Convert.ToString(dr["SystemStatus"]);
                if (!Convert.IsDBNull(dr["Deposite"]))
                    objcmsAccountDO.Deposite = Convert.ToInt64(dr["Deposite"]);
                if (!Convert.IsDBNull(dr["DepositBeforeTran"]))
                    objcmsAccountDO.DepositBeforeTran = Convert.ToInt64(dr["DepositBeforeTran"]);
                if (!Convert.IsDBNull(dr["Note"]))
                    objcmsAccountDO.Note = Convert.ToString(dr["Note"]);

            }
            return objcmsAccountDO;
        }

        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsAccount_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrcmsAccountDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    cmsAccountDO objcmsAccountDO = new cmsAccountDO();
                    if (!Convert.IsDBNull(dr["AccountId"]))
                        objcmsAccountDO.AccountId = Convert.ToInt32(dr["AccountId"]);
                    if (!Convert.IsDBNull(dr["AccountCode"]))
                        objcmsAccountDO.AccountCode = Convert.ToString(dr["AccountCode"]);
                    if (!Convert.IsDBNull(dr["CustomerId"]))
                        objcmsAccountDO.CustomerId = Convert.ToInt32(dr["CustomerId"]);
                    if (!Convert.IsDBNull(dr["CustomerCode"]))
                        objcmsAccountDO.CustomerCode = Convert.ToString(dr["CustomerCode"]);
                    if (!Convert.IsDBNull(dr["CreatedDate"]))
                        objcmsAccountDO.CreatedDate = Convert.ToDateTime(dr["CreatedDate"]);
                    if (!Convert.IsDBNull(dr["LastSaveDate"]))
                        objcmsAccountDO.LastSaveDate = Convert.ToDateTime(dr["LastSaveDate"]);
                    if (!Convert.IsDBNull(dr["CreatedById"]))
                        objcmsAccountDO.CreatedById = Convert.ToInt32(dr["CreatedById"]);
                    if (!Convert.IsDBNull(dr["LastModifiedId"]))
                        objcmsAccountDO.LastModifiedId = Convert.ToInt32(dr["LastModifiedId"]);
                    if (!Convert.IsDBNull(dr["SystemStatus"]))
                        objcmsAccountDO.SystemStatus = Convert.ToString(dr["SystemStatus"]);
                    if (!Convert.IsDBNull(dr["Deposite"]))
                        objcmsAccountDO.Deposite = Convert.ToInt64(dr["Deposite"]);
                    if (!Convert.IsDBNull(dr["DepositBeforeTran"]))
                        objcmsAccountDO.DepositBeforeTran = Convert.ToInt64(dr["DepositBeforeTran"]);
                    if (!Convert.IsDBNull(dr["Note"]))
                        objcmsAccountDO.Note = Convert.ToString(dr["Note"]);
                    arrcmsAccountDO.Add(objcmsAccountDO);
                }
            }
            return arrcmsAccountDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsAccount_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable AccountInfo(int customerId)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "cmsAccount_GetAccountInfo";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@CustomerId", SqlDbType.Int);
            Sqlparam.Value = customerId;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public cmsAccountDO AccountInfoObject(int customerId)
        {
            cmsAccountDO objcmsAccountDO = new cmsAccountDO();
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "cmsAccount_GetAccountInfo";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@CustomerId", SqlDbType.Int);
            Sqlparam.Value = customerId;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["AccountId"]))
                    objcmsAccountDO.AccountId = Convert.ToInt32(dr["AccountId"]);
                if (!Convert.IsDBNull(dr["AccountCode"]))
                    objcmsAccountDO.AccountCode = Convert.ToString(dr["AccountCode"]);
                if (!Convert.IsDBNull(dr["CustomerId"]))
                    objcmsAccountDO.CustomerId = Convert.ToInt32(dr["CustomerId"]);
                if (!Convert.IsDBNull(dr["CustomerCode"]))
                    objcmsAccountDO.CustomerCode = Convert.ToString(dr["CustomerCode"]);
                if (!Convert.IsDBNull(dr["CreatedDate"]))
                    objcmsAccountDO.CreatedDate = Convert.ToDateTime(dr["CreatedDate"]);
                if (!Convert.IsDBNull(dr["LastSaveDate"]))
                    objcmsAccountDO.LastSaveDate = Convert.ToDateTime(dr["LastSaveDate"]);
                if (!Convert.IsDBNull(dr["CreatedById"]))
                    objcmsAccountDO.CreatedById = Convert.ToInt32(dr["CreatedById"]);
                if (!Convert.IsDBNull(dr["LastModifiedId"]))
                    objcmsAccountDO.LastModifiedId = Convert.ToInt32(dr["LastModifiedId"]);
                if (!Convert.IsDBNull(dr["SystemStatus"]))
                    objcmsAccountDO.SystemStatus = Convert.ToString(dr["SystemStatus"]);
                if (!Convert.IsDBNull(dr["Deposite"]))
                    objcmsAccountDO.Deposite = Convert.ToInt64(dr["Deposite"]);
                if (!Convert.IsDBNull(dr["DepositBeforeTran"]))
                    objcmsAccountDO.DepositBeforeTran = Convert.ToInt64(dr["DepositBeforeTran"]);
                if (!Convert.IsDBNull(dr["Note"]))
                    objcmsAccountDO.Note = Convert.ToString(dr["Note"]);

            }
            return objcmsAccountDO;
        }
        public DataTable AccountInfo(string customerCode)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "cmsAccount_GetAccountInfoByCode";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@CustomerCode", SqlDbType.NVarChar);
            Sqlparam.Value = customerCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        #endregion

    }

}
